﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Net;
using System.Runtime.Serialization.Json;
using ServicioLugares.Objetos;

namespace ServicioLugares
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RutaLugares" in code, svc and config file together.
    public class RutaLugares : IRutaLugares
    {
        public RutaLugar GetDetalleLugar(string latOrigen, string lonOrigen, string latDestino, string lonDestino, string modo)
        {
            string url = string.Format(
                "http://maps.googleapis.com/maps/api/directions/json?origin={0},{1}&destination={2},{3}&sensor=false&mode={4}",
                latOrigen, lonOrigen, latDestino, lonDestino, modo
                );
            var request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RutaLugar));
            var res = (RutaLugar)serializer.ReadObject(request.GetResponse().GetResponseStream());
            return res;
        }
    }
}
